layui.use(['form','layer','jquery','layedit','laydate'],function (){
    var form = layui.form,
        layer = parent.layer == undefined ? layui.layer : parent.layer,
        jquery = layer.$;

    jquery("#userlogin").click(function (data){
        console.log(data.field);
        var name=jquery("#name").val();//用户名
        var code= jquery("#code").val();//账号
        var password=jquery("#password").val();//密码
        var verifycode=jquery("#verifycode").val();//密码
        var formData = new formData($("#form")[0]);
        if(name == null || name == ""){
            layer.close(index);
            top.layer.msg("用户名为空");
        }else if(code == null || code == ""){
            layer.close(index);
            top.layer.msg("账号为空");
        }else if(password == null || password == "") {
            layer.close(index);
            top.layer.msg("密码为空");
        }else {
            jquery.ajax({
                url: "/user/register",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                beforeSend: function () {
                    //返回的参数item，即为当前的input DOM对象
                    index = layer.load(1, {shade: [0.3, 'grey']});
                },
                //处理成功
                success: function (res) {
                    layer.close(index);
                    location.href = "/";
                    if (res.success == true) {
                        layer.msg(res.msg, {icon: 1, time: false}, function () {
                            refreshParent();
                        })
                    } else {
                        layer.msg(res.msg, {icon: 2, time: false})
                    }
                },
                error: function (res) {
                    layer.msg(res, {icon: 2, time: false});
                },
                complete: function () {

                }

            });
        }
        // return false;
    });
    // jquery("#userlogin").click(function (){
    //     var index = top.layer.msg('正在注册，请稍后',{icon: 16, time: false, shade: 0.8});
    //     var name = jquery("#name").val();//用户名
    //     var code = jquery("#code").val();//账号
    //     var password = jquery("#password").val();//密码
    //     var verifycode = jquery("#verifycode").val();//验证码
    //     var formData = new FormData($("#form")[0]);
    //     if (name == null || name == ""){
    //         layer.close(index);
    //         top.layer.msg("姓名为空");
    //     }else if(code == null || code == ""){
    //         layer.close(index);
    //         top.layer.msg("账号为空");
    //     }else if(password == null || password == "") {
    //         layer.close(index);
    //         top.layer.msg("密码为空");
    //     }else if(verifycode == null || verifycode == ""){
    //         layer.close(index);
    //         top.layer.msg("验证码为空")
    //     }else {
    //         jquery.ajax({
    //             url: "user/register",
    //             type: "post",
    //             data: formData,
    //             // data: {
    //             //     "name": name,
    //             //     "code": code,
    //             //     "password": password,
    //             //     "verifycode": verifycode
    //             // }
    //             success: function (result){
    //                 layer.close(index);
    //                 top.layer.msg(result.msg);
    //                 location.href = "/";
    //             }
    //         })
    //     }
    // })
});
/*刷新验证码*/
function refreshVerify() {
    var myData = new Date();
    var times = myData.getTime();
    $("#verify").attr("src", "/common/verifyCode/getVerifyCode?times=" + times);
}